﻿/*
 * Created by SharpDevelop.
 * User: ratul
 * Date: 3/2/2010
 * Time: 8:10 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using H264Impl.NET.Sample;

namespace H264Impl.NET
{
	/// <summary>
	/// Description of Macroblock.
	/// </summary>
	public class Macroblock : Block
	{
		public Macroblock()
		{
			
		}
		public const UInt32 macroblockWidth = 16;
		public const UInt32 macroblockHeight = 16;
		

		
		public Macroblock(SampleArrayFactory.SamplingType samplingType, bool separateColorPlane) : base(samplingType, macroblockWidth, macroblockHeight, separateColorPlane)
		{
			
		}
		UInt32 MacroblockType;
		
		enum NameOfMacroblockType
		{
			I_NxN,
			I_16x16_0_0_0,
			I_16x16_1_0_0,
			I_16x16_2_0_0,
			I_16x16_3_0_0,
			I_16x16_0_1_0,
			I_16x16_1_1_0,
			I_16x16_2_1_0,
			I_16x16_3_1_0,
			I_16x16_0_2_0,
			I_16x16_1_2_0,
			I_16x16_2_2_0,
			I_16x16_3_2_0,
			I_16x16_0_0_1,
			I_16x16_1_0_1,
			I_16x16_2_0_1,
			I_16x16_3_0_1,
			I_16x16_0_1_1,
			I_16x16_1_1_1,
			I_16x16_2_1_1,
			I_16x16_3_1_1,
			I_16x16_0_2_1,
			I_16x16_1_2_1,
			I_16x16_2_2_1,
			I_16x16_3_2_1,
			I_PCM,
			SI,
			P_L0_16x16,
			P_L0_L0_16x8,
			P_L0_L0_8x16,
			P_8x8,
			P_8x8ref0,
			P_Skip,
			B_Direct_16x16,
			B_L0_16x16,
			B_L1_16x16,
			B_Bi_16x16,
			B_L0_L0_16x8,
			B_L0_L0_8x16,
			B_L1_L1_16x8,
			B_L1_L1_8x16,
			B_L0_L1_16x8,
			B_L0_L1_8x16,
			B_L1_L0_16x8,
			B_L1_L0_8x16,
			B_L0_Bi_16x8,
			B_L0_Bi_8x16,
			B_L1_Bi_16x8,
			B_L1_Bi_8x16,
			B_Bi_L0_16x8,
			B_Bi_L0_8x16,
			B_Bi_L1_16x8,
			B_Bi_L1_8x16,
			B_Bi_Bi_16x8,
			B_Bi_Bi_8x16,
			B_8x8,
			B_Skip,
		}
		 
		public enum MacroblockPartitionPredictionMode
		{
			Intra_4x4,
			Intra_8x8,
			Intra_16x16,
			Pred_L0,
			Pred_L1,
			BiPred,
			Direct,
			Inter
		}
		
		NameOfMacroblockType nameOfMacroblockType;
		UInt32 NoOfMacroblockPartitions;
		MacroblockPartitionPredictionMode macroblockPartitionPredictionMode_0;
		MacroblockPartitionPredictionMode macroblockPartitionPredictionMode_1;
		bool transformSize8x8Flag;
		UInt32 intra16x16PredMode;
		UInt32 codedBlockPatternChroma;
		UInt32 codedBlockPatternLuma;
		UInt32 macroblockPartitionWidth;
		UInt32 macroblockPartitionHeight;
		
		UInt32 pcmAlignmentZeroBit;
		BaseSample[] pcmSampleLuma;
		BaseSample[] pcmSampleChroma;
		UInt32 codedBlockPattern;
		UInt32 mbQpDelta;
		
		
		
		public SpatialLocation inverseMacroblockScan(UInt32 pictureWidthinSamples)
		{
			SpatialLocation loc = new SpatialLocation();
			loc.x = Utility.InverseRasterScan(blockAddress, macroblockWidth, macroblockHeight, pictureWidthinSamples, false);
			loc.y = Utility.InverseRasterScan(blockAddress, macroblockWidth, macroblockHeight, pictureWidthinSamples, true);
			return loc;
		
		}
		
		
	}
}
